const router = require('koa-router')();
const koaBody = require('koa-body')();
const request = require('superagent'); //不要忘记npm install
var config=require('../config/app.config');
const co = require('co')

module.exports = router.post('/viewpoints/add', koaBody,co.wrap(function*(ctx) {
    // 添加观点
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/viewpoints/add')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;

})).post('/viewpoints/query', koaBody,co.wrap(function*(ctx) {
    // 查询观点
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/viewpoints/query')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;

})).post('/viewpoints/doFavort', koaBody,co.wrap(function*(ctx) {
    // 点赞 or 取消赞
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/viewpoints/doFavort')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;

})).post('/topics/query', koaBody,co.wrap(function*(ctx) {
    // 话题列表
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/topics/query')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
})).post('/topics/info', koaBody,co.wrap(function*(ctx) {
    // 话题详情
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/topics/info')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
})).post('/topics/queryCommit', koaBody,co.wrap(function*(ctx) {
    // 查询话题评论
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/topics/queryCommit')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
})).post('/topics/addComment', koaBody,co.wrap(function*(ctx) {
    // 添加话题评论
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/topics/addComment')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
})).post('/viewpoints/info', koaBody,co.wrap(function*(ctx) {
    // 观点详情
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/viewpoints/info')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
})).post('/viewpoints/queryPointComment', koaBody,co.wrap(function*(ctx) {
    // 观点评论
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/viewpoints/queryPointComment')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
})).post('/viewpoints/addPointComment', koaBody,co.wrap(function*(ctx) {
    // 添加观点评论
    let reqJson= ctx.request.body;
    reqJson['orgId']=config.orgId;
    reqJson['merchantId']=config.merchantId;
    var res = yield request
    .post(config.host+'/api/cms/viewpoints/addPointComment')
    .send(reqJson)
    .set('X-API-Key', 'foobar')
    .set('Accept', 'application/json')
    .set('Content-Type', 'application/json');
    console.log(res.body);
    ctx.response.body = res.body;
}))